package net.valerijtimakov.homefinances.dao.storages.finances.mysql;

import java.util.Map;
import net.valerijtimakov.homefinances.dao.storages.common.mysql.OwnedNamedItemsStorage;
import net.valerijtimakov.homefinances.dao.storages.finances.IAccountStorage;
import net.valerijtimakov.homefinances.domain.common.DataItem;
import net.valerijtimakov.homefinances.domain.finances.AccountItem;
import net.valerijtimakov.homefinances.exceptions.AppExceptionWrongState;
import net.valerijtimakov.homefinances.exceptions.AppPersProviderException;
import net.valerijtimakov.homefinances.exceptions.AppPersistentException;
import net.valerijtimakov.homefinances.exceptions.wrongarg.AppExceptionNullArgument;

public class AccountStorage extends OwnedNamedItemsStorage implements IAccountStorage {

	public AccountStorage(IMySqlProvider provider) throws AppExceptionWrongState {
		super(provider);
	}

	@Override
	protected DataItem createTempItem() {
		return new AccountItem();
	}
	
	@Override
	protected String getTableName() {
		return "account";
	}

	public Map<Long, AccountItem> getAllUserAccounts(long userId) 
		throws AppPersProviderException, AppExceptionWrongState 
	{
		return getAllUserItems(userId);
	}

	public Map<Long, AccountItem> getAccounts(long... id) 
		throws AppPersProviderException, AppExceptionWrongState 
	{
		return getItemsByIds(id);
	}

	public void addAccount(AccountItem item) throws AppPersistentException, 
		AppExceptionNullArgument, AppExceptionWrongState 
	{
		addItem(item, "Не задан экземпляр счета!", "Ошибка добавления счета!");
	}

	public void removeAccount(long id) throws AppPersProviderException, AppExceptionWrongState {
		delete(id);
	}

	public void updateAccount(AccountItem item) throws AppPersProviderException, AppExceptionWrongState {
		update(item);
	}

}
